GtkGesture *multipress_gesture;
gint handle_x;
- gint offset;
gint64 start_time;
gint64 end_time;
guint tick_id;
if (now < priv->end_time)
{
gdouble t;
- gint dest_offset;
+ gint dest_offset, start_offset;
if (priv->is_active)
- dest_offset = 0;
+ {
+ start_offset = gtk_widget_get_allocated_width (GTK_WIDGET (sw)) / 2;
+ dest_offset = 0;
+ }
else
- dest_offset = gtk_widget_get_allocated_width (GTK_WIDGET (sw)) / 2;
+ {
+ start_offset = 0;
+ dest_offset = gtk_widget_get_allocated_width (GTK_WIDGET (sw)) / 2;
+ }
t = (now - priv->start_time) / (gdouble) (priv->end_time - priv->start_time);
t = ease_out_cubic (t);
- priv->handle_x = priv->offset + t * (dest_offset - priv->offset);
+ priv->handle_x = start_offset + t * (dest_offset - start_offset);
}
else
{
GdkFrameClock *clock = gtk_widget_get_frame_clock (GTK_WIDGET (sw));
priv->start_time = gdk_frame_clock_get_frame_time (clock);
priv->end_time = priv->start_time + 1000 * ANIMATION_DURATION;
- priv->offset = priv->handle_x;
if (priv->tick_id == 0)
priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (sw),
gtk_switch_on_frame_clock_update,
gtk_widget_get_allocation (GTK_WIDGET (sw), &allocation);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
- if (priv->is_active)
- priv->offset = allocation.width / 2;
- else
- priv->offset = 0;
-
/* If the press didn't happen in the draggable handle,
* cancel the pan gesture right away
*/
{
GtkWidget *widget = GTK_WIDGET (sw);
GtkSwitchPrivate *priv = sw->priv;
- GtkAllocation allocation;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding;
offset = -offset;
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
- position = priv->offset + offset;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_restore (context);
- gtk_widget_get_allocation (widget, &allocation);
+ width = gtk_widget_get_allocated_width (widget);
- width = allocation.width;
+ if (priv->is_active)
+ position = width / 2 + offset;
+ else
+ position = offset;
/* constrain the handle within the trough width */
if (position > (width / 2) - padding.right)